#! /usr/bin/perl -w
#

# Author			: WangYongdong
# Email				: jjjarod@gmail.com
# Description	: Convert text format file to binary format
# Usage				: hex2bin.pl input_file output_file                
# Copyright (C) 2009 WangYongdong

$srcfile = $ARGV[0];
$destfile = $ARGV[1];

open INF, "$srcfile" or die "Can't open $srcfile for reading!\n";
open OUTF, ">$destfile" or die "Can't open $destfile for writing!\n";
binmode(OUTF);

while (<INF>)
{
		chomp;
    for $chunk (split(/\s+/, $_))
    {
        print OUTF pack("H8", $chunk); #use pack function to write data in binary format
    }
}
close(OUTF);
close(INF);